//app.js
var common = require("utils/util.js");

App({
  onLaunch: function () {
   
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        var that = this;
      common.ajax({
          url: 'PreRegistration/SmallProgramOpenID',
          data: {code:res.code},
          loading: '加载中...',
          userinfo: false,
          success: function (res) {
            // console.log(res)
              if (res.message == 'success') {
                  that.globalData.openId=res.openid;
              } else {
                  that.globalData.openId=res.openid;
              }
          }
      })
      }
    })
   
  },
  globalData: {
    userInfo: null,
    openId: ''
  }
})